package com.yanqu.road.server.cmd.activity.wanyao;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.WanYaoProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.wanyao.WanYaoModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_WAN_YAO_GET_USER_DATA, desc = "万妖行获取用户数据")
public class WanYaoGetUserDataCmd extends AbstractCommand {

    private int activityId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        WanYaoProto.WanYaoGetUserDataReq req = WanYaoProto.WanYaoGetUserDataReq.parseFrom(packet.getBytes());
        activityId = req.getActivityId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(WanYaoModule.class).getUserDataMsg(activityId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            WanYaoProto.WanYaoGetUserDataResp.Builder resp = WanYaoProto.WanYaoGetUserDataResp.newBuilder();
            resp.setRet(ret);
            player.sendPacket(ClientProtocol.U_WAN_YAO_GET_USER_DATA, resp);
        }
    }
}
